import static org.junit.Assert.assertEquals;

import java.awt.List;
import java.util.Date;
import java.util.LinkedList;

import models.EEntity;
import models.Organization;
import models.Role;
import models.RoleInEntity;
import models.RoleInOrganization;
import models.Topic;
import models.User;

import org.junit.Before;
import org.junit.Test;

import controllers.Application;

import play.test.Fixtures;
import play.test.UnitTest;

public class alaaTest1 extends UnitTest {

	@Before
	public void setUp() {
		Fixtures.deleteAll();
	}

	@Test
	
	
	public void Test(){
		User u1 = new User("OrganizationLead in public Organization.", "male",
				"PublicOrganizationLead", "OrganizationLead", new Date(),
				"thediamondknight1@gmail.com", "cairo").save();
		Organization o1 = new Organization("public", "I'm public Organization. oh yeah",
				0).save();
		EEntity e1 = new EEntity("1st entity in public organization",
				"cs and engineering department met lol ahmed", o1).save();
		EEntity e2 = new EEntity("2nd entity in public organization",
				"Communication and Engineering department", o1).save();
		EEntity e3 = new EEntity("3rd entity in public organization",
				"mechatronics and engineering department", o1).save();
		EEntity e4 = new EEntity("4th entity in public organization",
				"cs ahmed and engineering department", o1).save();
		o1.entities.add(e1);
		o1.entities.add(e2);
		o1.entities.add(e3);
		o1.entities.add(e4);
		o1.save();
		User u2 = new User("Organizer in 1st entity in public organization.",
				"male", "PublicOrganizer1", "Organizer", new Date(),
				"hamdymassoud@gmail.com", "cairo").save();
		Role role0=Role.findOrCreate("Orgnaizer").save();
		Role organizationLead =Role.findOrCreate("OrganizationLead").save();
		RoleInOrganization orglead=new RoleInOrganization(o1,u1,organizationLead).save();
		RoleInEntity role=new RoleInEntity(e1,u2,role0).save();
		u2.rolesAndEntities.add(role);
		u2.addRoleInOrganization(orglead).save();
		RoleInOrganization role2=new RoleInOrganization(o1,u2,role0).save();
		u2.rolesAndOrganization.add(role2);
		assertEquals(2,User.getUsers().size());
		assertEquals(1,o1.getEntitiesOfOrganizer(u2.id).size());
		assertEquals(u1.id,o1.organizationLead());
		
		

	}
}
